package main

import "fmt"

type State interface {
	Switch(ctx *Context)
}

type OnState struct {
}

func (o *OnState) Switch(ctx *Context) {
	fmt.Println("关机")
	ctx.SetState(new(OffState))
}

type OffState struct {
}

func (o *OffState) Switch(ctx *Context) {
	fmt.Println("开机")
	ctx.SetState(new(OnState))
}

type Context struct {
	state State
}

func (c *Context) SetState(state State) {
	c.state = state
}

func (c *Context) Switch() {
	c.state.Switch(c)
}

func main() {
	ctx := &Context{state: new(OffState)}
	ctx.Switch()

	ctx.Switch()
}
